﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TLT.Models.Entities;
using TLT.Models.ShopruviDatabase;
using TLT.Models.Repositories;

namespace TLT.Models.UOW
{
    public class UOW:IDisposable
    {
        private ShopruviContext context = new ShopruviContext();

        private  DanTocRepository danTocRepository;
        public DanTocRepository DanTocRepository
        {
            get
            {
                if (this.danTocRepository == null)
                {
                    this.danTocRepository = new DanTocRepository(context);
                }
                return danTocRepository;
            }
        }

        private DonViTinhRepository donViTinhRepository;
        public DonViTinhRepository DonViTinhRepository
        {
            get
            {
                if (this.donViTinhRepository == null)
                {
                    this.donViTinhRepository = new DonViTinhRepository(context);
                }
                return donViTinhRepository;
            }
        }

        private HangSanXuatRepository hangSanXuatRepository;
        public HangSanXuatRepository HangSanXuatRepository
        {
            get
            {
                if (this.hangSanXuatRepository == null)
                {
                    this.hangSanXuatRepository = new HangSanXuatRepository(context);
                }
                return hangSanXuatRepository;
            }
        }

        private KhachHangRepository khachHangRepository;
        public KhachHangRepository KhachHangRepository
        {
            get
            {
                if (this.khachHangRepository == null)
                {
                    this.khachHangRepository = new KhachHangRepository(context);
                }
                return khachHangRepository;
            }
        }

        private KhachHangTaiKhoanRepository khachHangTaiKhoanRepository;
        public KhachHangTaiKhoanRepository KhachHangTaiKhoanRepository
        {
            get
            {
                if (this.khachHangTaiKhoanRepository == null)
                {
                    this.khachHangTaiKhoanRepository = new KhachHangTaiKhoanRepository(context);
                }
                return khachHangTaiKhoanRepository;
            }
        }

        private KhoRepository khoRepository;
        public KhoRepository KhoRepository
        {
            get
            {
                if (this.khoRepository == null)
                {
                    this.khoRepository = new KhoRepository(context);
                }
                return khoRepository;
            }
        }

        private KhuVucRepository khuVucRepository;
        public KhuVucRepository KhuVucRepository
        {
            get
            {
                if (this.khuVucRepository == null)
                {
                    this.khuVucRepository = new KhuVucRepository(context);
                }
                return khuVucRepository;
            }
        }

        private KichCoRepository kichCoRepository;
        public KichCoRepository KichCoRepository
        {
            get
            {
                if (this.kichCoRepository == null)
                {
                    this.kichCoRepository = new KichCoRepository(context);
                }
                return kichCoRepository;
            }
        }

        private LoaiDoiTuongRepository loaiDoiTuongRepository;
        public LoaiDoiTuongRepository LoaiDoiTuongRepository
        {
            get
            {
                if (this.loaiDoiTuongRepository == null)
                {
                    this.loaiDoiTuongRepository = new LoaiDoiTuongRepository(context);
                }
                return loaiDoiTuongRepository;
            }
        }

        private LoaiSanPhamRepository loaiSanPhamRepository;
        public LoaiSanPhamRepository LoaiSanPhamRepository
        {
            get
            {
                if (this.loaiSanPhamRepository == null)
                {
                    this.loaiSanPhamRepository = new LoaiSanPhamRepository(context);
                }
                return loaiSanPhamRepository;
            }
        }

        private LoHangNhapRepository loHangNhapRepository;
        public LoHangNhapRepository LoHangNhapRepository
        {
            get
            {
                if (this.loHangNhapRepository == null)
                {
                    this.loHangNhapRepository = new LoHangNhapRepository(context);
                }
                return loHangNhapRepository;
            }
        }

        private MauSacRepository mauSacRepository;
        public MauSacRepository MauSacRepository
        {
            get
            {
                if (this.mauSacRepository == null)
                {
                    this.mauSacRepository = new MauSacRepository(context);
                }
                return mauSacRepository;
            }
        }

        private NganHangRepository nganHangRepository;
        public NganHangRepository NganHangRepository
        {
            get
            {
                if (this.nganHangRepository == null)
                {
                    this.nganHangRepository = new NganHangRepository(context);
                }
                return nganHangRepository;
            }
        }

        private NguonHangRepository nguonHangRepository;
        public NguonHangRepository NguonHangRepository
        {
            get
            {
                if (this.nguonHangRepository == null)
                {
                    this.nguonHangRepository = new NguonHangRepository(context);
                }
                return nguonHangRepository;
            }
        }

        private NhaCungCapRepository nhaCungCapRepository;
        public NhaCungCapRepository NhaCungCapRepository
        {
            get
            {
                if (this.nhaCungCapRepository == null)
                {
                    this.nhaCungCapRepository = new NhaCungCapRepository(context);
                }
                return nhaCungCapRepository;
            }
        }

        private NhaCungCapTaiKhoanRepository nhaCungCapTaiKhoanRepository;
        public NhaCungCapTaiKhoanRepository NhaCungCapTaiKhoanRepository
        {
            get
            {
                if (this.nhaCungCapTaiKhoanRepository == null)
                {
                    this.nhaCungCapTaiKhoanRepository = new NhaCungCapTaiKhoanRepository(context);
                }
                return nhaCungCapTaiKhoanRepository;
            }
        }

        private NhanVienRepository nhanVienRepository;
        public NhanVienRepository NhanVienRepository
        {
            get
            {
                if (this.nhanVienRepository == null)
                {
                    this.nhanVienRepository = new NhanVienRepository(context);
                }
                return nhanVienRepository;
            }
        }

        private NhaVanChuyenRepository nhaVanChuyenRepository;
        public NhaVanChuyenRepository NhaVanChuyenRepository
        {
            get
            {
                if (this.nhaVanChuyenRepository == null)
                {
                    this.nhaVanChuyenRepository = new NhaVanChuyenRepository(context);
                }
                return nhaVanChuyenRepository;
            }
        }

        private NhomKhachHangRepository nhomKhachHangRepository;
        public NhomKhachHangRepository NhomKhachHangRepository
        {
            get
            {
                if (this.nhomKhachHangRepository == null)
                {
                    this.nhomKhachHangRepository = new NhomKhachHangRepository(context);
                }
                return nhomKhachHangRepository;
            }
        }

        private NhomSanPhamRepository nhomSanPhamRepository;
        public NhomSanPhamRepository NhomSanPhamRepository
        {
            get
            {
                if (this.nhomSanPhamRepository == null)
                {
                    this.nhomSanPhamRepository = new NhomSanPhamRepository(context);
                }
                return nhomSanPhamRepository;
            }
        }

        private SanPhamHinhAnhRepository sanPhamHinhAnhRepository;
        public SanPhamHinhAnhRepository SanPhamHinhAnhRepository
        {
            get
            {
                if (this.sanPhamHinhAnhRepository == null)
                {
                    this.sanPhamHinhAnhRepository = new SanPhamHinhAnhRepository(context);
                }
                return sanPhamHinhAnhRepository;
            }
        }

        private SanPhamRepository sanPhamRepository;
        public SanPhamRepository SanPhamRepository
        {
            get
            {
                if (this.sanPhamRepository == null)
                {
                    this.sanPhamRepository = new SanPhamRepository(context);
                }
                return sanPhamRepository;
            }
        }

        private ThongTinCongTyRepository thongTinCongTyRepository;
        public ThongTinCongTyRepository ThongTinCongTyRepository
        {
            get
            {
                if (this.thongTinCongTyRepository == null)
                {
                    this.thongTinCongTyRepository = new ThongTinCongTyRepository(context);
                }
                return thongTinCongTyRepository;
            }
        }

        private TonGiaoRepository tonGiaoRepository;
        public TonGiaoRepository TonGiaoRepository
        {
            get
            {
                if (this.tonGiaoRepository == null)
                {
                    this.tonGiaoRepository = new TonGiaoRepository(context);
                }
                return tonGiaoRepository;
            }
        }

        private XaQuanHuyenThanhPhoRepository xaQuanHuyenThanhPhoRepository;
        public XaQuanHuyenThanhPhoRepository XaQuanHuyenThanhPhoRepository
        {
            get
            {
                if (this.xaQuanHuyenThanhPhoRepository == null)
                {
                    this.xaQuanHuyenThanhPhoRepository = new XaQuanHuyenThanhPhoRepository(context);
                }
                return xaQuanHuyenThanhPhoRepository;
            }
        }

        // Hệ Thống
        private NhomNguoiDungRepository nhomNguoiDungRepository;
        public NhomNguoiDungRepository NhomNguoiDungRepository
        {
            get
            {
                if (this.nhomNguoiDungRepository == null)
                {
                    this.nhomNguoiDungRepository = new NhomNguoiDungRepository(context);
                }
                return nhomNguoiDungRepository;
            }
        }

        // Save
        public void Save()
        {
            context.SaveChanges();
        }

        // Dispose
        private bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
